-- Project Ticket #38717 - 38717 A - Fix: Taking action off of Project Due and End Dates
-- The following is fixed: I changed the status and end date of project 0112801. The project end date was changed to 4/29/13 and the status was changed to active.
-- When I checked the project status today, it had changed to "over". It should not have changed to over until midnight on 4/30/13.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    ALTER PROCEDURE [dbo].[AllProcedureRelatedToOneDay]  AS BEGIN EXECUTE [dbo].[Donor_Awards]; EXECUTE [dbo]. [Projects]; EXECUTE [dbo].Projects_Penidng_active; EXECUTE [dbo].Projects_Active; END;      

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    ALTER PROCEDURE [dbo].[Donor_Awards] AS BEGIN DECLARE @statusidActive int; DECLARE @statusidOver int ; SELECT @statusidActive=ID from donorawardstatus where statusname='Active'; SELECT @statusidOver=ID from donorawardstatus where statusname='Over'; update donoraward set donorawardstatusid=@statusidOver where [donorawardstatusid]=@statusidActive and  datediff(day,enddate,getdate())>0;  END   

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    ALTER PROCEDURE [dbo].[Projects] AS BEGIN DECLARE @statusidActive int; DECLARE @statusidOver int ; SELECT @statusidActive=ID from projectstatus where statusname='Active'; SELECT @statusidOver=ID from projectstatus where statusname='Over'; update  project  set [projectstatusid]=@statusidOver where [projectstatusid]=@statusidActive  and datediff(day,projectenddate,getdate())>0;  END   

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    ALTER PROCEDURE [dbo].[Projects_Active]  AS BEGIN  DECLARE @statusidActive int; DECLARE @statusidPending int ; DECLARE @projectTypeIdPartener int;  SELECT @statusidActive=ID from projectstatus where statusname='Active'; SELECT @statusidPending=ID from projectstatus where statusname='Pending'; SELECT @projectTypeIdPartener=ID from [projecttype] where [projecttype]='Partner';  update project set [projectstatusid]=@statusidActive  where [projectstatusid]=@statusidPending and projecttypeid=@projectTypeIdPartener and   datediff(day,projectstartdate,getDate())>0  and riskassessmentscore is not null and receiptofsignedagreement is not null and receiptofbankinformation is not null and terroristcheckperformed='-1' and accountingquestionnairereceived='-1';  END   

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    ALTER PROCEDURE [dbo].[Projects_Penidng_active] AS BEGIN  DECLARE @statusidActive int; DECLARE @statusidPending int ; DECLARE @typeid int ; SELECT @statusidActive=ID from projectstatus where statusname='Active'; SELECT @statusidPending=ID from projectstatus where statusname='Pending'; SELECT @typeid=ID from [projecttype] where [projecttype]='Partner'  update  project set [projectstatusid]=@statusidActive where [projectstatusid]=@statusidPending and projecttypeid!=@typeid and datediff(day,projectstartdate,getdate())>0; END  

GO